﻿
//生成[OpRecord]Service代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FineAdmin.IService;
using FineAdmin.Model;
using FineAdmin.IRepository;
using FineAdmin.Common;

namespace FineAdmin.Service
{
    public class OpRecordService : BaseService<OpRecordModel>, IOpRecordService
    {
        public IOpRecordRepository OpRecordRepository { get; set; }
        public IEnumerable<OpRecordModel> GetOpRecordList()
        {
            return OpRecordRepository.GetOpRecordList();
        }


        public dynamic GetListByFilter(OpRecordModel filter, PageInfo pageInfo)
        {
            string _where = " where 1=1";
            return GetListByFilter(filter, pageInfo, _where);
        }

        public int AddOpRecord(string Name, string GName, int Count)
        {
            var opEntity = OpRecordRepository.GetByWhere("where Name=@Name and GName=@GName and MarkDate=@MarkDate", new { Name = Name, GName = GName, MarkDate = DateTime.Now.Date }).FirstOrDefault();
            if (opEntity != null)
            {

                opEntity.OpCount += Count;
                opEntity.UpdateTime = DateTime.Now;
                return OpRecordRepository.UpdateById(opEntity);
            }
            else
            {
                return OpRecordRepository.Insert(new OpRecordModel()
                {
                    OpCount = Count,
                    CreateTime = DateTime.Now,
                    GName = GName,
                    CreateUserId = 1,
                    Id = 1,
                    MarkDate = DateTime.Now.Date,
                    Name = Name,
                    SortCode = 0,
                    UpdateTime = DateTime.Now,
                    UpdateUserId = 1


                });
            }
        }
    }

}